//
//  SFUserCoordinator.swift
//  SeeFM_Swift
//
//  Created by CBCT_MBP on 2021/10/27.
//

import UIKit

class SFUserCoordinator: NSObject {

    public var userInfo: UserInfo?
    public weak var userVC: SFUserController?
    
    init(vc: SFUserController) {
        super.init()
        
        userVC = vc
        baseInit()
    }
    
    func setView(aClass: SFUserBaseView?) {
        guard let v = aClass else { return }
        let cn = NSStringFromClass(type(of: v))
        if !viewsHashTable.keys.contains(cn) {
            viewsHashTable[cn] = v
        }
    }
    
    func getView(aClass:SFUserBaseView?) -> SFUserBaseView? {
        guard let v = aClass else { return nil }
        return viewsHashTable[NSStringFromClass(type(of: v))]
    }
    
    fileprivate var viewsHashTable: [String:SFUserBaseView] = [:]
    var placeholder: SFUserPlaceholderView?
        
    func reloadComponent() {
        guard let v = userInfo else {
            placeholder?.isHidden = false
            return
        }
        placeholder?.isHidden = true
        // 重组View
        
    }
    
    func baseInit() {
        
        // set placeholder
        placeholder = SFUserPlaceholderView.viewWithCoordinator(coordinator: self) as? SFUserPlaceholderView
        guard let ph = placeholder else { return }
        userVC?.view.addSubview(ph)
        ph.snp.makeConstraints { make in
            make.left.top.right.bottom.equalToSuperview()
        }
        ph.assembleComponent(info: nil)
            
    }
    
    
}
